package service

import (
	"gitee.com/byx_darwin/geo-rpc/internal/base/conf"
	"gitee.com/byx_darwin/geo-rpc/kitex_gen/geo"
	"gitee.com/byx_darwin/micro-extend/pkg/errors/rpc"
	"github.com/cloudwego/kitex/pkg/klog"
	"github.com/pkg/errors"
)

type Service struct {
	log  klog.CtxLogger
	conf *conf.Config
	repo GeoRepo
}

type RequestArgument interface {
	IsValid() error
}

func NewService(repo GeoRepo,
	c *conf.Config,
	log klog.CtxLogger) geo.Service {
	return &Service{
		log:  log,
		conf: c,
		repo: repo,
	}
}

func (s *Service) CheckArgument(argument RequestArgument) error {
	err := argument.IsValid()
	if err != nil {
		return rpc.NewBizStatusError(rpc.ErrorTypeDataInvalid, errors.Wrap(err, "invalid request"))
	}
	return nil
}
